<script setup>
import { introApi } from "@/services/index";
import { onLoad, onShow } from "@dcloudio/uni-app";
import { nextTick, ref, watch, onMounted } from "vue";
import { appInfo, loginSwitch } from "@/services/user";

onLoad((e) => {
  code.value = e.code;
  getList();
});

const code = ref("");
const introData = ref([]);

const getList = async () => {
  try {
    // 发送请求
    let res = await appInfo({});

    if (res.code == 200) {
      introData.value = res.data.employees;
    }
  } catch (e) {
    console.log(e);
    uni.showToast({
      title: e.info,
      icon: "none",
    });
  }
};
const selectFun = async (item) => {
  try {
    // 发送请求
    let res = await loginSwitch({ shop: item.shopCode });
    if (res.code == 200) {
      uni.setStorageSync("X-Auth-Token", res.data.token);
      uni.setStorageSync("user", JSON.stringify(res.data.user));
      uni.reLaunch({ url: "/pages/index/index" });
      res.data.employees.forEach((item) => {
        if (item.shopCode == item.shopCode) {
        } else {
          uni.showToast({
            title: res.info,
            icon: "none",
          });
        }
      });
    }
  } catch (e) {
    uni.showToast({
      title: e.info,
      icon: "none",
    });
  }
};

const onClickLeft = () => history.back();
const onClickRight = () => showToast("按钮");

const themeVars = ref({
  navBarIconColor: "#000000",
  navBarTextColor: "#000000",
  navBarBackground: "transparent",
});
</script>

<template>
  <top-nav :title="' '" :border="false" rType="save"></top-nav>
  <!-- <van-config-provider :theme-vars="themeVars">
    <van-nav-bar
      title=" "
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
      @click-right="onClickRight"
      :safe-area-inset-top="true"
      :fixed="true"
      z-index="10"
      :placeholder="true"
    />
  </van-config-provider> -->
  <view class="content">
    <view class="content-title">请选择</view>
    <view class="content-des">登录后可切换 </view>
  </view>
  <view class="content-list">
    <view
      class="content-list-item"
      v-for="(item, index) in introData"
      :key="index"
      @click="selectFun(item)"
    >
      <view class="content-list-left">
        <view class="content-list-item-shop">{{ item.shopName }}</view>
        <view class="content-list-item-employeeNo"
          >{{ item.name }} {{ item.employeeNo }}</view
        >
      </view>
      <view class="content-list-right">
        <van-icon name="arrow" size="28rpx" color="#000000" />
      </view>
    </view>
  </view>
</template>

<style lang="scss" scoped>
@import "index.scss";
</style>
